#!/usr/bin/php
<?
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
ini_set("display_errors",1);
$path_event="/var/www/infopark_com_ua/data/www/infopark.com.ua/sites/default/files/event_thumbnail/";
$path_event_w220="/var/www/infopark_com_ua/data/www/infopark.com.ua/sites/default/files/styles/w220/public/event_thumbnail/";
$path_event_w150="/var/www/infopark_com_ua/data/www/infopark.com.ua/sites/default/files/styles/w150/public/event_thumbnail/";
$path_place="/var/www/infopark_com_ua/data/www/infopark.com.ua/sites/default/files/place_thumbnail/";
$path_place_w220="/var/www/infopark_com_ua/data/www/infopark.com.ua/sites/default/files/styles/w220/public/place_thumbnail/";
$path_place_w150="/var/www/infopark_com_ua/data/www/infopark.com.ua/sites/default/files/styles/w150/public/place_thumbnail/";
function resize($file,$thumbpath,$width)
{
$filename=substr($file,strrpos($file,"/")+1);
	if(!file_exists($thumbpath.$filename))
		{
		print $filename."\n";
			#$image = new Imagick($file);
		list($source_image_width, $source_image_height, $source_image_type) = getimagesize($file);
    switch ($source_image_type) {
        case IMAGETYPE_GIF:
            $source_gd_image = imagecreatefromgif($file);
            break;
        case IMAGETYPE_JPEG:
            $source_gd_image = imagecreatefromjpeg($file);
            break;
        case IMAGETYPE_PNG:
            $source_gd_image = imagecreatefrompng($file);
            break;
    }
			 $source_aspect_ratio = $source_image_width / $source_image_height;
			 $thumbnail_aspect_ratio = $width / (($width*$source_image_height)/$source_image_width);
			 $thumbnail_image_width = $width;
			 $thumbnail_image_height=(($width*$source_image_height)/$source_image_width);
			 $thumbnail_gd_image = imagecreatetruecolor($thumbnail_image_width, $thumbnail_image_height);
			  imagecopyresampled($thumbnail_gd_image, $source_gd_image, 0, 0, 0, 0, $thumbnail_image_width, $thumbnail_image_height, $source_image_width, $source_image_height);
			 switch ($source_image_type) {
					case IMAGETYPE_GIF:
						imagegif($thumbnail_gd_image, $thumbpath.$filename);
						break;
					case IMAGETYPE_JPEG:
						imagejpeg($thumbnail_gd_image, $thumbpath.$filename, 90);
						break;
					case IMAGETYPE_PNG:
						imagepng($thumbnail_gd_image, $thumbpath.$filename);
						break;
				}		 
			#imagejpeg($thumbnail_gd_image, $thumbpath.$filename, 90);
			imagedestroy($source_gd_image);
			imagedestroy($thumbnail_gd_image);
			
			
			
			#die("### GOOD FINALL ###");
		}


}
$files=glob($path_event."*");
foreach($files as $file)
	{
	resize($file,$path_event_w220,220);
	resize($file,$path_event_w150,150);
	}
$files=glob($path_place."*");
foreach($files as $file)
	{
	resize($file,$path_place_w220,220);
	resize($file,$path_place_w150,150);
	}
?>